package org.dromara.app.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.bean.domain.HisGoodsOrder;
import org.dromara.bean.domain.HisGoodsOrderEvaluate;
import org.dromara.bean.domain.HisRegistration;
import org.dromara.bean.domain.vo.HisGoodsOrderEvaluateVo;
import org.dromara.bean.mapper.HisGoodsOrderEvaluateMapper;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bean.domain.vo.HisGoodsOrderVo;
import org.dromara.bean.domain.bo.HisGoodsOrderBo;
import org.dromara.bean.service.IHisGoodsOrderService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 商城订单
 *
 * @author Lion Li
 * @date 2024-12-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/goodsOrder")
public class AHisGoodsOrderController extends BaseController {

    private final IHisGoodsOrderService hisGoodsOrderService;


    /**
     * 查询商城订单列表
     */
    @GetMapping("/list")
    public TableDataInfo<HisGoodsOrderVo> list(HisGoodsOrderBo bo, PageQuery pageQuery) {
        return hisGoodsOrderService.xcxQueryPageList(bo, pageQuery);
    }



    /**
     * 获取商城订单详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<HisGoodsOrderVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(hisGoodsOrderService.xcxQueryById(id));
    }

    /**
     * 新增商城订单
     */
    @Log(title = "商城订单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<?> add(@Validated(AddGroup.class) @RequestBody List<HisGoodsOrderBo> bo) {
        HisGoodsOrder order = hisGoodsOrderService.insertByBo(bo);
        return R.ok(order);
    }


    /**
     * 删除商城订单
     *
     * @param ids 主键串
     */
    @Log(title = "商城订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hisGoodsOrderService.xcxDeleteWithValidByIds(List.of(ids), true));
    }




    /**
     * 支付
     */
    @GetMapping("/pay")
    public  R<?>  pay( String orderNo) {
        return hisGoodsOrderService.pay(  orderNo, "2");
    }


    /**
     * 申请退款
     */
    @PutMapping()
    public R<?> update(@RequestBody HisGoodsOrder goodsOrder)  {
        return hisGoodsOrderService.update(goodsOrder);
    }


    /**
     * 撤销退款
     */
    @PutMapping("/ref")
    public R<?> ref(@RequestBody HisGoodsOrder goodsOrder)  {
        return hisGoodsOrderService.ref(goodsOrder);
    }

    /**
     * 确认收货
     */
    @PutMapping("/confirm")
    public R<?> confirm(@RequestBody HisGoodsOrder goodsOrder)  {
        return hisGoodsOrderService.confirm(goodsOrder);
    }

}
